/* GUI CONVERTED from ecwindow.i (converter v1.76) Fri Mar  1 10:06:37 2002 */
/* ecwindow.i - SCROLLING WINDOW INCLUDE FILE FOR ECN MAINTENANCE       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.3.1.5 $                                                         */
/*V8:ConvertMode=Maintenance                                            */
/* REVISION: 7.4    LAST MODIFIED: 07/21/93     BY: pma *H013* */
/* REVISION: 7.4    LAST MODIFIED: 04/06/95     BY: ame *H0CF* */
/* REVISION: 7.3    LAST MODIFIED: 12/16/95     BY: jzs *G1GS*            */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98     BY: *K1Q4* Alfred Tan     */
/* REVISION: 9.1    LAST MODIFIED: 08/14/00     BY: *N0KW* Jacolyn Neder  */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *G032*                    */
/* $Revision: 1.3.1.5 $    BY: John Pison            DATE: 02/07/02  ECO: *N18V*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*!

SCROLLS ON A SINGLE INDEX.  DOES NOT POP RESULT INTO CALLING PROGRAM.

{1} = file name
{2} = list of fields to display in frame. Must include
indexed field #1
{3} = indexed field #1 name
{4} = indexed field #1 use-index e.g. "use-index pt_part"
{5} = additional search criteria or "yes" if no
additional search criteria
{6} = frame title
{7} = additional frame phrase statements
{8} = frame
{9} = fields to highlight (must include {3})
{10} = "false" to allow empty window.

Assumptions:
1.  Indexed field is the highest order variant field,
that is it is either the highest order index field
or all higher order index fields will not vary
due to the additional search criteria
*/


FORM /*GUI*/ 
with frame w{8} row window_row scroll 1 window_down down overlay no-validate
   {7} title
   color normal {6} BGCOLOR 8 /*GUI*/.


if first_time then do with frame w{8}:
   frame_val_save = frame-value.

   hide message no-pause.
   status input off.
   status default stline[4]. /* Replace old way of doing status-line */

   find first {1} where {5} no-lock no-error.
   if not available {1} then do:

      {pxmsg.i &MSGNUM=5657 &ERRORLEVEL=1}
      hide message.
      leave.
   end.

   partial_ixval = "".
   partial_ixlen = length(partial_ixval).
   repeat while partial_ixlen > 0
         and substring(partial_ixval,partial_ixlen,1) = " ":
      partial_ixlen = partial_ixlen - 1.
   end.
   partial_ixval = substring(partial_ixval,1,partial_ixlen).

   field_nbr = 1.
end. /*if first_time*/

do with frame w{8}:
   clear frame w{8} all no-pause.
   ixlastline = 0.

   if global_recid <> ? then
      find first {1} where recid({1}) = global_recid no-lock no-error.

   if not available {1} then
   find first {1} where {3} >= partial_ixval and {5} {4}
   no-lock no-error.

   if not available {1} then
   find last  {1} where {3} <= partial_ixval and {5} {4}
   no-lock no-error.

   if not available {1} then
      find first {1} no-lock no-error.

   repeat while available {1} with frame w{8}:
      ixlastline = ixlastline + 1.
      ix1array[ixlastline] = {3}.
      recidarray[ixlastline] = recid({1}).
      display {2}.
      if frame-line = frame-down then leave.
      find next {1} where {5} {4} no-lock no-error.
      if available {1} then down 1.
      else leave.
   end.
   partial_ixval = substring(ix1array[1] + spcs,1,partial_ixlen).
   up ixlastline - 1.
   color prompt-for messages {9}.
end.

prompt-for {9} with frame w{8}
editing: /* GET A KEYSTROKE */
   do i = 1 to partial_ixlen:
      apply keycode("CURSOR-RIGHT").
   end.
   readkey.
   leave.
   /* THIS IS TO ELIMINATE THE COMPILE TIME WARNING      */
   /* SINCE THIS WINDOW IS NOT ACTUALLY ACCEPTING INPUT  */
   /* FOR THE PASSED VARIABLES - THIS FAKE ASSIGN IS AOK */
   assign {9}.
end. /* END GET A KEYSTROKE */

/* 32 TO 256 IS DISPLAYABLE ASCII CHARACTER RANGE */

repeat while lastkey = 8 or (lastkey >= 32 and lastkey <= 256)
      or lastkey = keycode("CURSOR-UP") or lastkey = keycode("CURSOR-DOWN")
      or lastkey = keycode("F9") or lastkey = keycode("F10")
      or lastkey = keycode("CURSOR-LEFT") or lastkey = keycode("CURSOR-RIGHT")
      or lastkey = keycode("F7") or lastkey = keycode("F8")
      or keyfunction(lastkey) = "page-down"
      or keyfunction(lastkey) = "page-up"
      or ({gpiswrap.i} and keyfunction(lastkey) = "HELP")
      or lastkey = 18 or lastkey = 26 /* CONTROL-R OR CONTROL-Z */
   with frame w{8}:
/*GUI*/ if global-beam-me-up then undo, leave.

   if {gpiswrap.i} and keyfunction(lastkey) = "HELP" then
      apply lastkey.
   else if lastkey = 8 or lastkey = keycode("CURSOR-LEFT") then do:
      if partial_ixlen > 0 then partial_ixlen = partial_ixlen - 1.
      partial_ixval = substring(partial_ixval + spcs,1,partial_ixlen).
   end.

   else if lastkey = keycode("CURSOR-RIGHT") then do:
      if length(ix1array[frame-line]) > partial_ixlen then do:
         partial_ixlen = partial_ixlen + 1.
         partial_ixval = substring(ix1array[frame-line] + spcs,1,partial_ixlen).
      end.
   end.

   else if lastkey >= 32 and lastkey <= 256 then do:
      partial_ixval = partial_ixval + chr(lastkey).
      partial_ixlen = partial_ixlen + 1.
      if partial_ixval > ix1array[ixlastline]
         or partial_ixval < ix1array[1]
      then do:
         find first {1} where {3} >= partial_ixval and {5} {4} no-lock no-error.
         if available {1} then do:
            if {3} = ix1array[1] then do:

               up frame-line - 1.
               color prompt-for messages {9}.
               partial_ixval = substring(ix1array[1] + spcs,1,partial_ixlen).
            end.
            else do:
               clear frame w{8} all no-pause.
               ixlastline = 0.
               find first {1} where {3} >= partial_ixval
                  and {5} {4} no-lock no-error.
               repeat while available {1} with frame w{8}:
                  ixlastline = ixlastline + 1.
                  ix1array[ixlastline] = {3}.
                  recidarray[ixlastline] = recid({1}).
                  display {2}.
                  if frame-line = frame-down then leave.
                  find next {1} where {5} {4} no-lock no-error.
                  if available {1} then down 1.
               end.
               partial_ixval = substring(ix1array[1] + spcs,1,partial_ixlen).
               up ixlastline - 1.
               color prompt-for messages {9}.
            end.
         end.
         else do:
            if partial_ixlen > 1 then partial_ixlen = partial_ixlen - 1.
            partial_ixval = substring(partial_ixval + spcs,1,partial_ixlen).
         end.
      end.
      else do:
         /* LOCATE FIRST SCREEN ELEMENT >= partial_ixval */
         i = 1.
         do while ix1array[i] < partial_ixval:
            i = i + 1.
         end.
         up frame-line - i.  /* NEGATIVE EXPR HERE IS down */
         color prompt-for messages {9}.
         partial_ixval = substring(ix1array[i] + spcs,1,partial_ixlen).
      end.
   end.

   else if lastkey = keycode("CURSOR-UP") or lastkey = keycode("F9")
   then do:
      if frame-line = 1 then do:
         find {1} where recid({1}) = recidarray[1] no-lock no-error.
         find prev {1} where {5} {4} no-lock no-error.
         if available {1} then do:
            clear frame w{8} all no-pause.
            ixlastline = 0.
            repeat while available {1} with frame w{8}:
               ixlastline = ixlastline + 1.
               ix1array[ixlastline] = {3}.
               recidarray[ixlastline] = recid({1}).
               display {2}.
               if frame-line = frame-down then leave.
               find next {1} where {5} {4} no-lock no-error.
               if available {1} then down 1.
            end.
            partial_ixval =  substring(ix1array[1] + spcs,1,partial_ixlen).
            up ixlastline - 1.
            color prompt-for messages {9}.
         end.
         else do.
            {pxmsg.i &MSGNUM=21 &ERRORLEVEL=2} /* "Beginning of file"*/
         end.
      end.
      else do:

         up 1.
         color prompt-for messages {9}.
         partial_ixval = substring(ix1array[frame-line] + spcs,1,partial_ixlen).
      end.
   end.

   else if lastkey = keycode("CURSOR-DOWN") or lastkey = keycode("F10")
   then do:
      if frame-line = ixlastline then do:
         find {1} where recid({1}) = recidarray[ixlastline] no-lock no-error.
         find next {1} where {5} {4} no-lock no-error.
         if available {1} then do:

            down 1.
            display {2}.
            color prompt-for messages {9}.
            do i = 1 to ixlastline:
               ix1array[i] = ix1array[i + 1].
               recidarray[i] = recidarray[i + 1].
            end.
            ix1array[ixlastline] = {3}.
            recidarray[ixlastline] = recid({1}).
            partial_ixval = substring(ix1array[ixlastline] + spcs,1,partial_ixlen).
         end.
         else do.
            {pxmsg.i &MSGNUM=20 &ERRORLEVEL=2} /* "End of file"*/
         end.
      end.
      else do:

         down 1.
         color prompt-for messages {9}.
         partial_ixval = substring(ix1array[frame-line] + spcs,1,partial_ixlen).
      end.
   end.

   else if lastkey = keycode("F7")
      or keyfunction(lastkey) = "page-up"
      or lastkey = 18 then do:
      /* PAGE BACKWARD */
      find {1} where recid({1}) = recidarray[1] no-lock no-error.
      find prev {1} where {5} {4} no-lock no-error.
      if available {1} then do:
         do i = 1 to frame-down - 2 while available {1}:
            find prev {1} where {5} {4} no-lock no-error.
         end.
         if not available {1} then
         find first {1} where {5} {4}
         no-lock no-error.

         clear frame w{8} all no-pause.
         ixlastline = 0.

         repeat while available {1} with frame w{8}:
            ixlastline = ixlastline + 1.
            ix1array[ixlastline] = {3}.
            recidarray[ixlastline] = recid({1}).
            display {2}.
            if frame-line = frame-down then leave.
            find next {1} where {5} {4} no-lock no-error.
            if available {1} then down 1.
         end.
         partial_ixval =  substring(ix1array[1] + spcs,1,partial_ixlen).

         up (ixlastline - 1).
         color prompt-for messages {9}.
      end.
   end.

   else if lastkey = keycode("F8")
      or keyfunction(lastkey) = "page-down"
      or lastkey = 26 then do:
      /* PAGE FORWARD */
      find {1} where recid({1}) = recidarray[ixlastline] no-lock no-error.
      clear frame w{8} all no-pause.
      ixlastline = 0.
      repeat while available {1} with frame w{8}:
         ixlastline = ixlastline + 1.
         ix1array[ixlastline] = {3}.
         recidarray[ixlastline] = recid({1}).
         display {2}.
         if frame-line = frame-down then leave.
         find next {1} where {5} {4} no-lock no-error.
         if available {1} then down 1.
      end.
      partial_ixval =  substring(ix1array[1] + spcs,1,partial_ixlen).

      up (ixlastline - 1).
      color prompt-for messages {9}.
   end.

   prompt-for {9} with frame w{8}
   editing: /* GET A KEYSTROKE */
      do i = 1 to partial_ixlen:
         apply keycode("CURSOR-RIGHT").
      end.
      readkey.
      leave.
      /* THIS IS TO ELIMINATE THE COMPILE TIME WARNING      */
      /* SINCE THIS WINDOW IS NOT ACTUALLY ACCEPTING INPUT  */
      /* FOR THE PASSED VARIABLES - THIS FAKE ASSIGN IS AOK */
      assign {9}.
   end. /* END GET A KEYSTROKE */
   assign wtemp3 = string(input {3}).  /*just to stop compile warning*/
end.
/*GUI*/ if global-beam-me-up then undo, leave.


i = frame-line(w{8}).

pause before-hide.
